<?php 

	session_start();
	require_once "../common/PinSQL.obj";
	
	$username = $_SESSION['destuser'];
	$pinSQL = new PinSQL();
	
	error_reporting(0);
	$write = "";
	$write = $_GET['write'];
	error_reporting(1);
	
	$pinSQL->Query("SELECT * FROM members WHERE username='$username'");
	$row = $pinSQL->FetchNextRow();
	$id = $row['id']; // gets ID of currently viewed user*/
	
	if ($id == $_SESSION['id'])
	{
		$name = $_SESSION['username'];
		$pinSQL->Query("UPDATE buzz SET isread=1 WHERE touser='$name'");
	}
	
?>

<head>
	<link rel="stylesheet" type="text/css" href="profile_inner.css" />
</head>

<?php $context = "buzz"; include "otheruser_returnheader.php" ?>

<div class="padded_text">

	<div class="head"><?php echo $username; ?>'s buzz</div>
	
	<div class="horizontal_separation"></div>

	<div class="item">
	
		<img src="/img/arrow_white.gif" />
		<a href="javascript:ShowHideCommentBox()">Write on <?php echo $username; ?>'s buzz</a>
		
		<div id="commentdiv" style="display: <?php echo ($write) ? "block" : "none" ?>;">
			<span id="comment_status" style="display: none; font-size: 9pt;">Please wait...<img src="/img/rotating_arrow.gif" style="position: relative; top: 4px;"></span>

				<blockquote>
				<textarea name="comment" id="comment" rows=3 cols=50></textarea>
				</blockquote>
				<input type="hidden" name="destuser" value="<?php echo $username ?>" >
		
			<img src="/img/arrow_green.gif" /><a href="javascript:PostComment();"> Post Comment</a>
		</div>
		
	</div>
	
	<div class="horizontal_separation"></div>
	
	<div id="comments">
		<?php include "gen_buzz.php"; ?>
	</div>

</div>



<script type="text/javascript">

	function ShowHideCommentBox()
	{
          commentBlock = document.getElementById('commentdiv');
          
          if (commentBlock.style.display == 'block')
          {
               commentBlock.style.display = 'none';
          } else {
               commentBlock.style.display = 'block';
          }
	}
	
	function PostComment()
	{
          statusBlock = document.getElementById('comment_status');
          statusBlock.style.display = 'block';
          
          commentBlock = document.getElementById('commentdiv');

          // create the XMLHttpRequest object
          var request;
          try { request = new XMLHttpRequest(); }
          catch(e)
          {
               try { request = new ActiveXObject("Msxml2.XMLHTTP"); }
               catch(e)
               {
                    try { request = new ActiveXObject("Microsoft.XMLHTTP"); }
                    catch(e)
                    {
                         alert("Your browser will not support this webpage.");
                         return false;
                    }
               }
          }

          
          request.open("POST", 'post_comment.php', true);

          request.onreadystatechange = function()
          {
               if(request.readyState == 4)
               {
                    var responseText = request.responseText;
                    statusBlock.style.display = 'none';
                    commentBlock.style.display = 'none';
                    document.getElementById('comments').innerHTML = responseText;
               }
          }

		request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		request.send('destuser=<?php echo $username; ?>&comment=' + document.getElementById('comment').value); 

     }
     
	function DeleteComment(commentId)
	{
          // create the XMLHttpRequest object
          var request;
          try { request = new XMLHttpRequest(); }
          catch(e)
          {
               try { request = new ActiveXObject("Msxml2.XMLHTTP"); }
               catch(e)
               {
                    try { request = new ActiveXObject("Microsoft.XMLHTTP"); }
                    catch(e)
                    {
                         alert("Your browser will not support this webpage.");
                         return false;
                    }
               }
          }
          
          request.open("POST", 'delete_comment.php', true);
          
          request.onreadystatechange = function()
          {
               if(request.readyState == 4)
               {
                    var responseText = request.responseText;
                    document.getElementById('comments').innerHTML = responseText;
               }
          }

		request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		request.send('commentid=' + commentId); 
 	}
	
</script>